import os


def remove_blank_lines_in_dir(directory):
    for filename in os.listdir(directory):
        if filename.endswith(".txt"):  # 只处理 .txt 文件
            file_path = os.path.join(directory, filename)
            with open(file_path, 'r', encoding='utf-8') as file:
                lines = file.readlines()

            with open(file_path, 'w', encoding='utf-8') as file:
                file.writelines(line for line in lines if line.strip())  # 过滤空白行


# 使用示例
remove_blank_lines_in_dir(r"E:\2025-03-20_17_16_09_merge")  # 替换 "A" 为你的目标目录路径
